package com.flash.BusinessParameters.service.impl;

import com.flash.BusinessParameters.entity.FundSetting;
import com.flash.BusinessParameters.mapper.FundSettingMapper;
import com.flash.BusinessParameters.service.FundSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FundSettingServiceImpl implements FundSettingService {
    @Resource
    FundSettingMapper fundSettingMapper;

    public int deleteFundSetting(int fundId) {
        return fundSettingMapper.deleteFundSetting(fundId);
    }
    /**
     *
     * @param fundSetting 基金名称
     * @param page 当前页
     * @param limit 每页显示的条数
     * @return 基金 的集合
     */
    public List<FundSetting> selectFundSettingMap(FundSetting fundSetting, int page, int limit) {
        Map hashMap=new HashMap();
        System.out.println(fundSetting);
        hashMap.put("strWhere",buildStrWhere(fundSetting));
        hashMap.put("page",(page-1)*limit+1);
        hashMap.put("limit",limit*page);
        return fundSettingMapper.selectFundSettingMap(hashMap);
    }

    /**
     * 生成SQL条件
     * @param fundSetting 实体类
     * @return  条件的字符串  where 1=1 “   and userName  like '%admin%' and roleId =1 ”
     */
    public String buildStrWhere(FundSetting fundSetting){
        StringBuffer strWhere=new StringBuffer("");
        int intWhere =0;
        if(fundSetting.getFundId()!=null && !fundSetting.getFundId().equals(""))
        {
            System.out.println("22222"+fundSetting.getFundId());
            strWhere.append("and fundId like '%" + fundSetting.getFundId() + "%'");
        }
        if(fundSetting.getFundName()!=null && !fundSetting.getFundName().equals(""))
        {
            strWhere.append("and fundName like '%" + fundSetting.getFundName() + "%'");
        }
        if(fundSetting.getFundType()!=0)
        {
            strWhere.append(" and fundType =" + fundSetting.getFundType());
        }

        return strWhere.toString();
    }

    public List<FundSetting> selectFundSetting() {
        return fundSettingMapper.selectFundSetting();
    }

    public int updateFundSetting(FundSetting fundSetting) {
        return fundSettingMapper.updateFundSetting(fundSetting);
    }

    public int insertFundSetting(FundSetting fundSetting) {
        return fundSettingMapper.insertFundSetting(fundSetting);
    }

    public int selectCountFundSetting() {
        return fundSettingMapper.selectCountFundSetting();
    }

}
